package com.xr.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xr.mapper.RoleMapper;
import com.xr.pojo.Role;
import com.xr.query.QueryPageBean;
import com.xr.result.PageResult;
import com.xr.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;



    //分页加条件查询
    @Override
    public PageResult findPage(QueryPageBean queryPageBean) {
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        Page<Role> page = roleMapper.selectByFindString(queryPageBean.getQueryString());
        return new PageResult(page.getTotal(),page.getResult());
    }

    @Override
    public void AddRolePermission(Role role, Integer[] PermissionIds) {

        //1.除了检查组的数据需要新增
        roleMapper.insertSelective(role);
        //1.1 需要修改SQL代码，返回id值
        int roleId = role.getId();
        //2.检查组和套餐的第三方表的数据也需要新增
        if (PermissionIds != null && PermissionIds.length > 0) {
            roleMapper.AddRolePermission(roleId, PermissionIds);
        }

    }
}
